﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style>
        .i-full-screen{
            width: 100%; height: 100%;
            border: none;
            display: inline;
        }
        .root{
             height:100%; max-height:100%; overflow:hidden; border:0; padding:0; margin:0;
        }
    </style>
    <script src="js/lib/jquery-1.6.1.min.js"></script>
    <script src="js/lib/jquery.ba-postmessage.js"></script>
    <script src="js/lib/jquery.iframe.js"></script>
    <script src="js/ezdesk/iindexservice.js"></script>
    <script>

        var indexService;

        var serviceLocation = {
            serviceBaseUrl: "",
            modulePaths: { LoginModulePath: "login.html",
                NotificationModulePath: "notification.html",
                MiniMainModulePath: "minimain.html",
                MainModulePath: "main.html"
            },
            init: function (serviceBaseUrl) {
                this.serviceBaseUrl = serviceBaseUrl;
                for (var q in this.modulePaths) {
                    this[q] = serviceBaseUrl + this.modulePaths[q];
                }
            }
        };
        var application = {
            currentState: 'begin',
            min: function () {
                miniMainModule.init();
                $('#i-login').hide();
                $("#i-mini-main").show();
                $("#i-main").hide();
                indexService.setTopMost(true);
                application.currentState = 'min';
            },
            normal: function () {
                $('#i-login').hide();
                $("#i-mini-main").hide();
                $("#i-main").show();
                indexService.setTopMost(false);
                application.currentState = 'normal';
            },
            begin: function () {
                indexService.createTray();

                $('#i-login').show();
                $('#i-main').hide();
                $('#i-mini-main').hide();
                $('#div-notification').hide();

                application.currentState = 'begin';
            },
            onLogin: function (result) {
                if (result) {
                    mainModule.init();
                    notificationModule.init();
                    application.normal();
                }
            },
            onMessage: function (e) {
                var paramKeyRegex = /\w*(?=\:)/g;
                var key = paramKeyRegex.exec(e.data);

                key = key ? key[0] : e.data;
                if (key == 'min')
                    application.min();
                if (key == 'normal')
                    application.normal();
                if (key == 'close')
                    application.min();
                if (key == 'notification')
                    notificationModule.showNotification(e.data.substring(key.length + 1));
                if (key == 'notification-hide')
                    notificationModule.hideNotification();
                if (key == 'url')
                    indexService.newWindow(e.data.substring(key.length + 1));
                if (key == 'login')
                    application.onLogin(e.data.substring(key.length + 1));
            }


        };
        var notificationModule = {
            init: function () {
                $('#i-notification').src(serviceLocation.NotificationModulePath);
            },
            showNotification: function (desireHeight) {
                var $NotificationIframe = $('#div-notification').height(parseInt(desireHeight) + 25);
                $NotificationIframe.fadeIn();
            },
            hideNotification: function () {
                var $NotificationIframe = $('#div-notification');
                $NotificationIframe.fadeOut();
            }
        };
        var loginModule = {
            init: function () {
                $('#i-login').src(serviceLocation.LoginModulePath);
            }

        };
        var mainModule = {
            init: function () {
                $('#i-main').src(serviceLocation.MainModulePath);
            }
        };
        var miniMainModule = {
            init: function () {
                $('#i-mini-main').src(serviceLocation.MiniMainModulePath);
            }
        };

        $(function () {
            indexService = GetIndexService();
            $.receiveMessage(application.onMessage);
            serviceLocation.init("http://localhost:20501/app/");
            loginModule.init();
            application.begin();
        });
    </script>
</head>
<body class="root">
    <iframe id="i-login" class="i-full-screen"></iframe>
    <iframe id="i-main" class="i-full-screen"></iframe>
    <iframe id="i-mini-main" class="i-full-screen"></iframe>
    <div id="div-notification" style="height: 300px; width: 500px; position: absolute; bottom: 0px; right: 0px; float: right;">
        <iframe id="i-notification" class="i-full-screen"></iframe>
    </div>
</html>
